<template>
  <van-skeleton animate :row="30" :loading="loading"></van-skeleton>
</template>

<script lang="ts" setup>
import { login, getToken, setCache } from '@/services/user'
import { useRouter } from 'vue-router'
import { useUserStore, useComtokenStore } from '@/stores'
import { ticket } from '@/utils/cuturl'
import { ref, onMounted } from 'vue'
const store = useUserStore()
const sttokne = useComtokenStore()
const loading = ref(true)

const obj: any = ref({})
const router = useRouter()
const getdata = async () => {
  const res = await login(obj.value)
  store.setUser(res)
  if (res.code === 200) {
    gettoken()
    router.push('/home')
    loading.value = false
  }
}

const gettoken = async () => {
  const res = await getToken()
  sttokne.setToken(res.token)
}
onMounted(() => {
  if (import.meta.env.VITE_DPING_DEV == 'pro') {
    const url = window.location.href
    obj.value = ticket(url)
    store.setLoginAccount(obj.value)
    if (Object.values(obj.value).length) {
      getdata()
    } else {
      loading.value = false
      router.push('/404')
    }
  } else {
    // gethc()
    obj.value = {
      zlbUserId: '000000005e75149d015e78ed865001b5',
      userType: '1',
      cubeUserId: '6322c9f0a881225cb20d8f0b'
    }
    getdata()
  }
})
</script>

<style lang="scss" scoped></style>
